<template>
  <div>
    <ul :key="index" class="card" v-for="(item, index) in data">
      <div class="card-mask"></div>
      <li :key="ind" v-for="(ite, ind) in item">
        <div class="card-item">
          <div class="card-img">
            <div>{{ite.key}}</div>
            <!-- <img :src="`https://images.weserv.nl/?url=${ite.img}`" /> -->
            <img :src="ite.img" />
          </div>
          <div class="card-content">
            <div class="name">{{ite.name}}</div>
            <div class="author">
              - {{ite.author}}
              <a-icon class="star" theme="filled" type="star" />
              {{ite.nstar}}
            </div>
            <div class="intro">{{ite.comment}}</div>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import dataConfig from './config';

// 分组
const data = dataConfig.pyBookTop250;
const num = 5; // 每25一组
const list = [];
data.forEach((item, index) => {
  item.key = index + 1;
  const page = Math.floor(index / num);
  if (!list[page]) {
    list[page] = [];
  }
  list[page].push({
    ...item,
    rate: item.rate / 2,
    nstar: item.rate,
  });
});
console.log(list);

export default {
  data() {
    return {
      data: list,
    };
  },
  methods: {},
};
</script>

<style lang="less" scoped>
.card {
  position: relative;
  box-sizing: border-box;
  width: 375px;
  height: 500px;
  background-image: url('/static/images/m1.jpg');
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
  margin-bottom: 10px;
}

.card-mask {
  position: absolute;
  width: 375px;
  height: 500px;
  background-color: rgba(0, 0, 0, 0.75);
}

.card-item {
  padding: 0 10px 0 20px;
  display: flex;
}

.card-content {
  color: #ffffff;
  z-index: 9999;
  margin-left: 10px;

  .name {
    font-size: 16px;
    font-weight: bold;
  }

  .author {
    font-size: 12px;
  }

  .star {
    color: #fadb14;
    margin-left: 10px;
  }

  .intro {
    margin-top: 5px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
    word-break: break-all;
    word-wrap: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
}

.card-img {
  position: relative;
  div {
    position: absolute;
    line-height: normal;
    background-color: rgba(206, 155, 78, 0.9);
    text-align: center;
    padding: 3px 0;
    width: 30px;
    border-radius: 0 0 30px 0;
  }
  img {
    width: 55px;
    height: auto;
  }
}
</style>
